<template>
  <el-dialog title="稽查注册ip用户" :visible.sync="visible" width="800px" top="5vh" append-to-body
             :close-on-click-modal="false">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="会员名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入会员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table v-loading="loading" ref="table" :data="userList" height="260px">
        <el-table-column label="会员id" align="center" key="id" prop="id"
                         :show-overflow-tooltip="true" width="80"
        />
        <el-table-column label="会员名称" align="center" key="name" prop="name"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="会员手机号" align="center" key="phone" prop="phone"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column prop="ip_status" label="ip状态" width="80">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.customer_ip_status" :value="scope.row.ip_status"/>
          </template>
        </el-table-column>
        <el-table-column label="注册ip" align="center" key="register_ip" prop="register_ip"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="注册地区" align="center" key="register_address" prop="register_address"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column sortable="custom" label="活期账户" align="center" key="total_amount" prop="total_amount"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column sortable="custom" label="智能账户" align="center" key="total_ai_amount" prop="total_ai_amount"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column sortable="custom" label="所在层级" align="center" key="level" prop="level"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column sortable="custom" label="团队充值" align="center" key="team_deposit" prop="team_deposit"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column sortable="custom" label="团队提现" align="center" key="team_withdraw" prop="team_withdraw"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="上级代理" align="center" key="agent_name" prop="agent_name"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="一级代理" align="center" key="first_agent_name" prop="first_agent_name"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="注册时间" align="center" key="create_time" prop="create_time" width="160"/>
        <el-table-column label="登录ip" align="center" key="login_ip" prop="login_ip"
                         :show-overflow-tooltip="true" width="160"
        />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="0"
              @change="handleStatusChange(scope.row)"
              v-if="scope.row.included"
            ></el-switch>
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"
                      v-if="!scope.row.included"/>
          </template>
        </el-table-column>
        <el-table-column prop="quantification_status" label="量化状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.quantification_status"
              :active-value="1"
              :inactive-value="0"
              @change="handleQuantificationStatusChange(scope.row)"
              v-if="scope.row.included"
            ></el-switch>
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.quantification_status"
                      v-if="!scope.row.included"/>
          </template>
        </el-table-column>
        <el-table-column prop="withdraw_status" label="提现状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.withdraw_status"
              :active-value="1"
              :inactive-value="0"
              @change="handleWithdrawStatusChange(scope.row)"
              v-if="scope.row.included"
            ></el-switch>
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.withdraw_status"
                      v-if="!scope.row.included"/>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.page_size"
        @pagination="getList"
      />
    </el-row>
  </el-dialog>
</template>

<script>
import {listUserV4, updateUser} from "@/api/customer/customer";

export default {
  name: "SelectRegisterIpCustomer",
  dicts: ['sys_normal_disable', 'customer_ip_status'],
  props: {
    app_id: {
      type: [Number, String]
    },
  },
  data() {
    return {
      loading: true,
      // 遮罩层
      visible: false,
      // 选中数组值
      user_ids: [],
      // 总条数
      total: 0,
      // 未授权用户数据
      userList: [],
      // 查询参数
      queryParams: {
        page: 1,
        page_size: 10,
        name: undefined,
        app_id: undefined,
        register_ip: undefined,
      }
    };
  },
  methods: {
    // 显示弹框
    show(register_ip) {
      this.queryParams.page = 1
      this.queryParams.page_size = 10
      this.queryParams.name = undefined
      this.queryParams.register_ip = register_ip;
      this.queryParams.app_id = this.app_id;
      this.getList();
      this.visible = true;
    },
    // 查询表数据
    getList() {
      this.loading = true
      listUserV4(this.queryParams).then(res => {
        this.userList = res.data;
        this.total = res.total;
        this.loading = false
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleStatusChange(row) {
      updateUser({id: row.id, status: row.status}).then(response => {
        this.$modal.msgSuccess('修改成功')
        this.getList()
      })
    },
    handleQuantificationStatusChange(row) {
      updateUser({id: row.id, quantification_status: row.quantification_status}).then(response => {
        this.$modal.msgSuccess('修改成功')
        this.getList()
      })
    },
    handleWithdrawStatusChange(row) {
      updateUser({id: row.id, withdraw_status: row.withdraw_status}).then(response => {
        this.$modal.msgSuccess('修改成功')
        this.getList()
      })
    }
  }
};
</script>
